<template>
    <div>
        <div>
            <checkbox-app-source v-model="row.sources" ref="sourcesSelected"></checkbox-app-source>
        </div>
        <div style="margin-top: 30px">
            <el-button type="primary" @click="submit" :loading="loading">保存</el-button>
            <el-button @click="cancel">返回</el-button>
        </div>
    </div>

</template>

<script>
import CheckboxAppSource from "~/components/Checkbox/app-source.vue";

export default {
    props: {
        row:{}
    },
    components: {
        CheckboxAppSource

    },
    data() {
        return {
            loading: false,
            form: {
                id: '',
                sources: []
            },
            appSources: this.$store.state.appSource.all,
            submitLoading: false
        }
    },
    methods: {
        getFormAction() {
        },
        submit() {
            this.submitLoading = true;
            this.form.sources = this.$refs.sourcesSelected.selected.sort()
            this.form.id = this.$props.row.id
            this.$store.dispatch('smsSign/Update', this.form).then(res => {
                this.$message.success(res.data.message);
                this.$emit('submit');
            }).finally(() => {
                this.submitLoading = false;
            });
        },
        cancel() {
            this.$emit('cancel');
        },
        getAppSources() {
            if (this.appSources.length === 0) this.$store.dispatch('appSource/All', 'appSource');
        },
    },
    created() {
        this.getAppSources();
    }
}
</script>

<style lang="scss" scoped>
.item-row {
    margin: 0 0 10px 0;
}
</style>

